fix(search-replace): don't auto-navigate when content edits invalidate the active match#4819
Conversation
…e the active match
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview When the active match drops out for other reasons, selection is cleared and the counter shows 0 of N until the user uses arrows. Replace records the current index so the next match is selected at that position (VS Code–style) instead of resetting to the first hit; failed applies clear that intent. Arrow navigation from a deselected state no longer skips the first or last match. Minor cleanup: panel close clears the editor search target; some handlers drop unnecessary Reviewed by Cursor Bugbot for commit 680fa11. Configure here. |
Greptile SummaryThis PR fixes a focus-stealing bug in the search-replace panel: when a user manually edits a block's content and causes the active match to disappear, the panel now deselects silently ("0 of N") instead of jumping to a different block mid-edit. It also aligns Replace-button navigation with VS Code behavior and fixes ↓ from a deselected state skipping the first match.
Confidence Score: 5/5Safe to merge — the fix is well-scoped, the stale-ref edge cases raised in prior review rounds are all addressed, and the navigation logic holds up across the key scenarios. All three stale-afterReplaceIndexRef paths discussed in prior threads are now closed: the committed flag + finally clears the ref on every failure path inside the try block, the ref write was moved past the top-level guard so a double-click during an in-flight apply cannot leave it set, and the zero-matches branch also clears it. The justOpened || queryChanged vs. content-edit distinction in the navigation effect is correct, and the deselected-state arrow-key fix matches the described VS Code behavior. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[hydratedMatches changes] --> B{isOpen?}
B -- No --> C[prevIsOpenRef = false\nsetActiveSearchTarget null\nreturn]
B -- Yes --> D[Compute justOpened\nCompute queryChanged\nUpdate prevQueryRef / prevIsOpenRef]
D --> E{hydratedMatches\nlength === 0?}
E -- Yes --> F[Clear afterReplaceIndexRef\nClear activeMatchId\nsetActiveSearchTarget null]
E -- No --> G{activeMatchId still\nin hydratedMatches?}
G -- Yes --> H[setActiveSearchTarget\nwith current match]
G -- No --> I[Read & clear\nafterReplaceIndexRef]
I --> J{queryChanged\nor justOpened?}
J -- Yes --> K[Navigate to\nhydratedMatches 0]
J -- No --> L{replaceIndex\n!== null?}
L -- Yes --> M[Navigate to\nMin replaceIndex, last match index]
L -- No --> N[Deselect: setActiveMatchId null\nsetActiveSearchTarget null\nShow 0 of N]
Reviews (5): Last reviewed commit: "fix(search-replace): revert !activeMatch..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3aeb9dc. Configure here.
…ly past the guard
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3475fe4. Configure here.
|
@greptile |
|
@cursor review |
…e re-navigation after deselect
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 680fa11. Configure here.
Summary
Type of Change
Testing
Tested manually
Checklist